package nextoffer.Tencent2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Five {
    public static void main(String[] args) {
        int n,k;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        int pos[] = new int[n];
        int color[] = new int[n];
        for(int i =0 ;i < n;i++){
            pos[i] = in.nextInt();
        }
        for(int i =0 ;i < n;i++){
            color[i] = in.nextInt();
        }
        int res = 0;
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 1 ;i < n - 1; i++){
                if(color[i] + color[i - 1]!= 0){
                    list.add(pos[i] + 1 - pos[i - 1]);
                    pos[i] = pos[i] + 1;
                    color[i] = 0;
                }
        }
        Collections.sort(list);
        for(int i = 0; i< list.size() - k;i++){
            res += list.get(i);
        }

        System.out.println(res);
    }
}
